package com.huabo.contract.mysql.mapper;


import com.hbfk.util.PageInfo;
import com.huabo.contract.mysql.entity.TblAttachmentMySql;
import com.huabo.contract.mysql.entity.TblCyhwUnitMySql;

import net.sf.json.JSONObject;

import java.math.BigDecimal;
import java.util.List;


import org.apache.ibatis.annotations.*;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author huabo
 * @since 2021-10-23
 */
@Mapper
public interface TblCyhwUnitMySqlMapper extends tk.mybatis.mapper.common.Mapper<TblCyhwUnitMySql> {

//	@Select("SELECT COUNT(0) FROM TBL_CYHW_UNIT WHERE CONTRACTXDFXINFO = #{budgetid}")
//	Integer selectListByBudgetId(@Param("budgetid")Integer budgetid) throws Exception;

	@Select("SELECT * FROM TBL_CYHW_UNIT WHERE CONTRACTID = #{contractid}")
	TblCyhwUnitMySql selectAllInfoById(BigDecimal contractid) throws Exception;


    @SelectProvider(type=TblCyhwUnitMySqlMapperSqlConfig.class,method="selectUnitListByPageInfo")
	List<TblCyhwUnitMySql> selectUnitListByPageInfo(PageInfo<TblCyhwUnitMySql> pageInfo, String orgid, String staffid, Integer paCount);

    @SelectProvider(type=TblCyhwUnitMySqlMapperSqlConfig.class,method="selectUnitCountByPageInfo")
    Integer selectUnitCountByPageInfo(PageInfo<TblCyhwUnitMySql> pageInfo, String orgid, String staffid, Integer paCount);

	@SelectProvider(type=TblCyhwUnitMySqlMapperSqlConfig.class,method="selectLedgerListPageInfo")
    List<TblCyhwUnitMySql> selectLedgerListPageInfo(PageInfo<TblCyhwUnitMySql> pageInfo);

	@SelectProvider(type=TblCyhwUnitMySqlMapperSqlConfig.class,method="selectLedgerCountPageIfo")
	Integer selectLedgerCountPageIfo(PageInfo<TblCyhwUnitMySql> pageInfo);

	@SelectProvider(type=TblCyhwUnitMySqlMapperSqlConfig.class,method="findLedgerListForExport")
    List<TblCyhwUnitMySql> findLedgerListForExport(TblCyhwUnitMySql unit);
	@SelectProvider(type=TblCyhwUnitMySqlMapperSqlConfig.class,method="findCollectionChoiceContractPid")
    List<TblCyhwUnitMySql> findCollectionChoiceContractPid(PageInfo<TblCyhwUnitMySql> pageInfo, BigDecimal pid,String contractno,String contractname);

	@SelectProvider(type=TblCyhwUnitMySqlMapperSqlConfig.class,method="findCollectionChoiceContractPidCount")
	Integer findCollectionChoiceContractPidCount(BigDecimal pid, String contractno, String contractname);

	@SelectProvider(type=TblCyhwUnitMySqlMapperSqlConfig.class,method="selectCountByPageInfo")
	Integer selectCountByPageInfo(BigDecimal pid, String contractno, String contractname);

	@InsertProvider(type=TblCyhwUnitMySqlMapperSqlConfig.class,method="insertCyhwUnit")
	@Options(useGeneratedKeys=true, keyProperty="contractid", keyColumn="CONTRACTID")
    void insertCyhwUnit(TblCyhwUnitMySql tcu);

	@Insert("INSERT INTO TBL_CYHW_UNIT_ATT(CONTRACTID,ATTID) VALUES(#{contractid},#{attId})")
	void insertAttmentRelation(@Param("attId")String id, @Param("contractid")BigDecimal contractid);

	@Select("SELECT CONTRACTSTATUS FROM TBL_CYHW_UNIT WHERE CONTRACTID = #{contractId}")
    Integer selectStatueById(Integer contractId);

	@UpdateProvider(method="updateCyhwUnit",type=TblCyhwUnitMySqlMapperSqlConfig.class)
    void updateCyhwUnit(TblCyhwUnitMySql tcu);

	@Select("SELECT * FROM TBL_CYHW_UNIT WHERE  CONTRACTID = #{contractId}")
	TblCyhwUnitMySql selectByContractId(BigDecimal contractId);

	@Update("UPDATE TBL_CYHW_UNIT SET CONTRACTSTATUS = #{contractstatus} WHERE CONTRACTID = #{contractid}")
	void updateContractStatus(TblCyhwUnitMySql entity);

	@Delete("DELETE FROM TBL_CONTRACT_PLANNODE WHERE PROJECTID = #{contractId}")
    void deletePlannode(Integer contractId);

	@Delete("DELETE FROM TBL_ATTACHMENT WHERE ATTID IN (SELECT ATTID FROM TBL_CYHW_UNIT_ATT WHERE CONTRACTID = #{contractId}) ")
	void deleteattachment(Integer contractId);

	@Delete("DELETE FROM TBL_CYHW_UNIT_ATT WHERE CONTRACTID = #{contractId}")
	void deleteUnitaTT(Integer contractId);

	@Delete("DELETE FROM TBL_CONTRACT_INFORMATION WHERE PROJECTID = #{contractId}")
	void deleteInformation(Integer contractId);

	@Delete("DELETE FROM TBL_CYHW_UNIT WHERE CONTRACTID = #{contractId}")
	void deleteunit(Integer contractId);

	@Select("SELECT * FROM TBL_CYHW_UNIT WHERE  CONTRACTID = #{contractId}")
	TblCyhwUnitMySql getCyhwUnitEntity(int contractId);

	@SelectProvider(type=TblCyhwUnitMySqlMapperSqlConfig.class,method="selectListByPageInfo")
    List<TblCyhwUnitMySql> selectListByPageInfo(PageInfo<TblCyhwUnitMySql> pageInfo, TblCyhwUnitMySql unit);

	@SelectProvider(type = TblCyhwUnitMySqlMapperSqlConfig.class,method = "selectCountByPageInfoCount")
	Integer selectCountByPageInfoCount(TblCyhwUnitMySql unit);

	@Select("SELECT * FROM TBL_CYHW_UNIT TCU\n" +
			"LEFT JOIN TBL_FLOW TF ON TCU.FLOWID = TF.FLOWID\n" +
			"WHERE CONTRACTID = #{contractId}")
	TblCyhwUnitMySql selectChangeContractInfo(BigDecimal contractid);

	@SelectProvider(type = TblCyhwUnitMySqlMapperSqlConfig.class,method = "findListByPageInfo")
    List<TblCyhwUnitMySql> findListByPageInfo(PageInfo<TblCyhwUnitMySql> pageInfo, String orgid);
	@SelectProvider(type = TblCyhwUnitMySqlMapperSqlConfig.class,method = "findCountByPageInfoCount")
	Integer findCountByPageInfoCount(PageInfo<TblCyhwUnitMySql> pageInfo, String orgid);

	@Select("SELECT * FROM TBL_CYHW_UNIT where CONTRACTID = #{contractId}")
	TblCyhwUnitMySql findContractById(Integer contractId);

	@Update("UPDATE TBL_CYHW_UNIT SET HISCONTRACTSTATUS = #{historyStatus},CONTRACTSTATUS = #{currentStatus} WHERE CONTRACTID = #{contractId} ")
    void updateModifyContractStatus(BigDecimal historyStatus, Integer currentStatus, BigDecimal contractId);

	@Update("UPDATE TBL_CYHW_UNIT SET  HISCONTRACTSTATUS = #{hiscontractstatus},CONTRACTSTATUS = #{hiscontractstatus1} WHERE CONTRACTID = #{contractid} ")
    void updateStatus(BigDecimal hiscontractstatus, BigDecimal hiscontractstatus1, BigDecimal contractid);

	@Select("SELECT CONTRACTMONEY FROM TBL_CYHW_UNIT WHERE CONTRACTID =#{contractId}")
    BigDecimal findContractMoneyByContractId(Integer contractId);

//	@Select("SELECT * FROM TBL_CYHW_UNIT WHERE RECORDTYPE = #{recordType} AND  CONTRACTID = #{parentId}")
//	TblCyhwUnit findeContractInfo(@Param("parentId") Integer parentId, @Param("recordType")String recordType);

		@Select("SELECT t.*,o.ORGMENO,s.REALNAME,c.COUNTERPARTNO,c.BUDGETNAME,c.TOTALTMONEY,c.COUNTERPARTTYPE,c.PROJECTSTAGEGOAL,c.COUNTERPARTADDRESS,c.COUNTERPARTPHONE,c.COUNTERPARTCODE,oz.ORGNAME,cb.BANKID,cb.BANKACCOUNT,cb.BANKKHYH FROM TBL_CYHW_UNIT t " +
				" left join TBL_ORGANIZATION o on t.CONTRACTDEPT = o.ORGID " +
				" left join TBL_STAFF s on t.CONTRACTSTAFF = s.STAFFID " +
				" left join TBL_CYHW_PROJECTBUDGET c on t.CONTRACTXDFXINFO = c.BUDGETID " +
				" left join TBL_ORGANIZATION oz on t.ZXUNIT = oz.ORGID " +
				" left join TBL_COUNTERPART_BANKINFO cb on t.COUNTERPARTBANK = cb.BANKID "+
				" WHERE t.RECORDTYPE = #{recordType} AND  t.CONTRACTID = #{parentId}")
		@Results({
				@Result(column="BANKID",property="bankinfo.bankid"),
				@Result(column="BANKACCOUNT",property="bankinfo.bankaccount"),
				@Result(column="BANKKHYH",property="bankinfo.bankkhyh")
		})
	TblCyhwUnitMySql findeContractInfo(@Param("parentId") Integer parentId, @Param("recordType")String recordType);

	@Select("SELECT CONTRACTID,FLOWID,CONTRACTNAME,CONTRACTNO,CONTRACTMONEY,CONTRACTTYPE,CREATETIME,RECORDTYPE FROM TBL_CYHW_UNIT WHERE CONTRACTID != #{contractid} START WITH CONTRACTID = #{contractid} CONNECT BY PRIOR RECORDPARENT = CONTRACTID ORDER BY CREATETIME DESC")
	List<TblCyhwUnitMySql> findAllParentList(BigDecimal contractid);

//	@Select("SELECT ATTID,ATTNAME,ATTPATH,ATTSIZE,MEMO,UPLOADTIME,UPLOADER FROM TBL_ATTACHMENT WHERE ATTID IN (SELECT ATTID FROM TBL_CYHW_PROJECTBUDGET_ATT WHERE BUDGETID IN (SELECT BUDGETID FROM TBL_CYHW_PROJECTBUDGET WHERE RECORDTYPE = 'HTGL003' AND ORGID = #{orgid} AND RECORDPARENT = #{contractId}))")
//	List<TblAttachment> findContractSealFileList(@Param("orgid")BigDecimal orgid,@Param("contractId")Integer contractId);
	
	@Select("SELECT ATTID,ATTNAME,ATTPATH,ATTSIZE,MEMO,UPLOADTIME,UPLOADER FROM TBL_ATTACHMENT WHERE ATTID IN (SELECT ATTID FROM TBL_CYHW_UNIT_ATT WHERE contractId = #{contractId})")
	List<TblAttachmentMySql> findContractSealFileList(@Param("orgid")BigDecimal orgid,@Param("contractId")Integer contractId);

	@SelectProvider(type = TblCyhwUnitMySqlMapperSqlConfig.class,method = "findContractSealList")
	List<TblCyhwUnitMySql> findContractSealList(PageInfo<TblCyhwUnitMySql> pageInfo);

	@SelectProvider(type = TblCyhwUnitMySqlMapperSqlConfig.class,method = "findCountContractSealList")
	Integer findCountContractSealList(PageInfo<TblCyhwUnitMySql> pageInfo);

	@Update("UPDATE TBL_CYHW_UNIT SET HISCONTRACTSTATUS = #{hiscontractstatus},CONTRACTSTATUS = #{currentStatus} WHERE CONTRACTID = #{contractid}")
    void updateModifyContrac(BigDecimal hiscontractstatus, BigDecimal currentStatus, BigDecimal contractid);

	@Update("UPDATE TBL_CYHW_UNIT SET HISCONTRACTSTATUS = #{hiscontractstatus},CONTRACTSTATUS=#{hiscontractstatus1} WHERE CONTRACTID = #{contractid}")
    void modifyContract(BigDecimal hiscontractstatus, BigDecimal hiscontractstatus1, BigDecimal contractid);

	@SelectProvider(type = TblCyhwUnitMySqlMapperSqlConfig.class,method = "findeFilContractList")
    List<TblCyhwUnitMySql> findeFilContractList(PageInfo<TblCyhwUnitMySql> pageInfo);

	@SelectProvider(type = TblCyhwUnitMySqlMapperSqlConfig.class,method = "findeCountFilContractList")
	Integer findeCountFilContractList(PageInfo<TblCyhwUnitMySql> pageInfo);

	@Select("SELECT * FROM TBL_CYHW_UNIT where RECORDPARENT = #{recordparent}")
	TblCyhwUnitMySql findContractByParentId(BigDecimal recordparent);

	@Update("UPDATE TBL_CYHW_UNIT SET CONTRACTSTATUS = #{status} WHERE CONTRACTID =  #{contractid} ")
	void modifyContractStatus(BigDecimal contractid, String status);

	@SelectProvider(type = TblCyhwUnitMySqlMapperSqlConfig.class,method = "findeContractListByContractStaff")
	List<TblCyhwUnitMySql> findeContractListByContractStaff(PageInfo<TblCyhwUnitMySql> pageInfo);
	@SelectProvider(type = TblCyhwUnitMySqlMapperSqlConfig.class,method = "findeCountContractListByContractStaff")
	Integer findeCountContractListByContractStaff(PageInfo<TblCyhwUnitMySql> pageInfo);

	@SelectProvider(type = TblCyhwUnitMySqlMapperSqlConfig.class,method = "findeContractListPerformanceTracking")
    List<TblCyhwUnitMySql> findeContractListPerformanceTracking(PageInfo<TblCyhwUnitMySql> pageInfo);

	@SelectProvider(type = TblCyhwUnitMySqlMapperSqlConfig.class,method = "findeCountContractListPerformanceTracking")
	Integer findeCountContractListPerformanceTracking(PageInfo<TblCyhwUnitMySql> pageInfo);

	@SelectProvider(type = TblCyhwUnitMySqlMapperSqlConfig.class,method = "findFulfillmentContract")
    List<TblCyhwUnitMySql> findFulfillmentContract(PageInfo<TblCyhwUnitMySql> pageInfo);

	@SelectProvider(type = TblCyhwUnitMySqlMapperSqlConfig.class,method = "findCountFulfillmentContract")
	Integer findCountFulfillmentContract(PageInfo<TblCyhwUnitMySql> pageInfo);

	@Update("UPDATE TBL_CYHW_UNIT SET HISCONTRACTSTATUS=CONTRACTSTATUS,CONTRACTSTATUS = #{goalStatus} WHERE CONTRACTID =  #{contractId}")
	void updaContractStatus(String contractId, int goalStatus);


	@SelectProvider(type = TblCyhwUnitMySqlMapperSqlConfig.class,method = "findLegalContractListByPageInfo")
    List<TblCyhwUnitMySql> findLegalContractListByPageInfo(PageInfo<TblCyhwUnitMySql> pageInfo, TblCyhwUnitMySql tcu);

	@SelectProvider(type = TblCyhwUnitMySqlMapperSqlConfig.class,method = "findLegalContractListByPageInfoCount")
	Integer findLegalContractListByPageInfoCount(TblCyhwUnitMySql tcu);

	@Select("SELECT * FROM TBL_CYHW_UNIT WHERE CONTRACTID= #{recordparent}")
	TblCyhwUnitMySql getEntity(Integer recordparent);

	@SelectProvider(type = TblCyhwUnitMySqlMapperSqlConfig.class,method = "findListByXdf")
    List<TblCyhwUnitMySql> findListByXdf(PageInfo<TblCyhwUnitMySql> pageInfo, String budgetid);

	@SelectProvider(type = TblCyhwUnitMySqlMapperSqlConfig.class,method = "findListByXdfCount")
	Integer findListByXdfCount(String budgetid);

	@SelectProvider(type = TblCyhwUnitMySqlMapperSqlConfig.class,method = "findListContractBiangengBypage")
    List<TblCyhwUnitMySql> findListContractBiangengBypage(PageInfo<TblCyhwUnitMySql> pageInfo, BigDecimal orgid, String userid, boolean findByModuel);

	@SelectProvider(type = TblCyhwUnitMySqlMapperSqlConfig.class,method = "findListContractBiangengBypageCount")
	Integer findListContractBiangengBypageCount(BigDecimal orgid, String userid, boolean findByModuel);

	@SelectProvider(type = TblCyhwUnitMySqlMapperSqlConfig.class,method = "findListByPage")
	List<TblCyhwUnitMySql> findListByPage(PageInfo<TblCyhwUnitMySql> pageInfo, BigDecimal orgid);

	@SelectProvider(type = TblCyhwUnitMySqlMapperSqlConfig.class,method = "findListByPageCount")
	Integer findListByPageCount(BigDecimal orgid);

	@SelectProvider(type = TblCyhwUnitMySqlMapperSqlConfig.class,method = "findListByPa")
	List<TblCyhwUnitMySql> findListByPa(PageInfo<TblCyhwUnitMySql> pageInfo, String userid, BigDecimal orgid);

	@SelectProvider(type = TblCyhwUnitMySqlMapperSqlConfig.class,method = "findListByPaCount")
	Integer findListByPaCount(String userid, BigDecimal orgid);

	@Select("SELECT CONTRACTID,FLOWID,CONTRACTNAME,CONTRACTNO,CONTRACTMONEY,CONTRACTTYPE,CREATETIME,RECORDTYPE FROM TBL_CYHW_UNIT WHERE CONTRACTXDFXINFO =#{budgetid}")
    List<TblCyhwUnitMySql> selectAllParentInfoList(Integer budgetid);

	@Select("SELECT CONTRACTID,FLOWID,CONTRACTNAME,CONTRACTNO,CONTRACTMONEY,CONTRACTTYPE,CREATETIME,RECORDTYPE FROM TBL_CYHW_UNIT WHERE CONTRACTXDFXINFO =#{budgetid}")
	List<TblCyhwUnitMySql> selectListByBudgetId(Integer budgetid);

	@Select("SELECT contractId,MOMOCONCAT,describe,contractName  FROM TBL_CYHW_UNIT WHERE recordType = 'HTGL007' AND contractType = #{contractType} AND orgid = #{orgid} AND contractStatus = 6")
    List<TblCyhwUnitMySql> selectContractTemp(BigDecimal orgid, String contractType);

	@Select("SELECT DESCRIBE FROM TBL_CYHW_UNIT WHERE CONTRACTID = #{budgetId}")
	String findContractDes(String budgetId);


	List<TblAttachmentMySql> findeFileInfo(Integer contractid);


	List<JSONObject> getList(String orgid, String startDate);




//	@Select("Select * from TBL_CYHW_UNIT_ATT where ATTID")
//	TblCyhwUnitAtt findByAttid(String id);


//	@InsertProvider(type = TblCyhwUnitMapperSqlConfig.class,method = "findLegalContractListByPageInfoCount")
//	void saveContractInfoMation(TblCyhwUnit tcu);
}
